home *** CD-ROM | disk | FTP | other *** search
- package com.simeda.ActiveViewer;
-
- import java.io.IOException;
- import java.util.Hashtable;
-
- public class KeyReader implements Runnable {
- public static final String keys_1 = ".,?!1@'-_():;^/%*#+<=>\"$";
- public static final String keys_2 = "abc2";
- public static final String keys_3 = "def3";
- public static final String keys_4 = "ghi4";
- public static final String keys_5 = "jkl5";
- public static final String keys_6 = "mno6";
- public static final String keys_7 = "pqrs7";
- public static final String keys_8 = "tuv8";
- public static final String keys_9 = "wxyz9";
- public static final String keys_0 = " 0";
- public static final Character numkey_0 = new Character('0');
- public static final Character numkey_1 = new Character('1');
- public static final Character numkey_2 = new Character('2');
- public static final Character numkey_3 = new Character('3');
- public static final Character numkey_4 = new Character('4');
- public static final Character numkey_5 = new Character('5');
- public static final Character numkey_6 = new Character('6');
- public static final Character numkey_7 = new Character('7');
- public static final Character numkey_8 = new Character('8');
- public static final Character numkey_9 = new Character('9');
- public static final Character numkey_pound = new Character('#');
- public static final Character numkey_star = new Character('*');
- Thread timer;
- boolean isRunning;
- boolean isCaps;
- rfbProto rfb;
- int lastKey;
- int keyPosition;
- Hashtable keys = new Hashtable();
- Hashtable numKeys = new Hashtable();
- vncCanvas theCanvas = null;
-
- public KeyReader(rfbProto var1, vncCanvas var2) {
- this.rfb = var1;
- this.theCanvas = var2;
- this.keys.put(new Integer(48), " 0");
- this.keys.put(new Integer(49), ".,?!1@'-_():;^/%*#+<=>\"$");
- this.keys.put(new Integer(50), "abc2");
- this.keys.put(new Integer(51), "def3");
- this.keys.put(new Integer(52), "ghi4");
- this.keys.put(new Integer(53), "jkl5");
- this.keys.put(new Integer(54), "mno6");
- this.keys.put(new Integer(55), "pqrs7");
- this.keys.put(new Integer(56), "tuv8");
- this.keys.put(new Integer(57), "wxyz9");
- this.numKeys.put(new Integer(48), numkey_0);
- this.numKeys.put(new Integer(49), numkey_1);
- this.numKeys.put(new Integer(50), numkey_2);
- this.numKeys.put(new Integer(51), numkey_3);
- this.numKeys.put(new Integer(52), numkey_4);
- this.numKeys.put(new Integer(53), numkey_5);
- this.numKeys.put(new Integer(54), numkey_6);
- this.numKeys.put(new Integer(55), numkey_7);
- this.numKeys.put(new Integer(56), numkey_8);
- this.numKeys.put(new Integer(57), numkey_9);
- this.numKeys.put(new Integer(35), numkey_pound);
- this.numKeys.put(new Integer(42), numkey_star);
- this.lastKey = -1;
- }
-
- public void run() {
- try {
- Thread.sleep(500L);
- } catch (InterruptedException var2) {
- }
-
- if (this.timer == Thread.currentThread()) {
- this.doSend();
- this.lastKey = -1;
- this.keyPosition = 0;
- }
-
- }
-
- public void toggleCaps() {
- this.isCaps = !this.isCaps;
- }
-
- public void doSend() {
- String var1 = (String)this.keys.get(new Integer(this.lastKey));
- int var2 = -1;
- if (var1 == null) {
- var2 = this.lastKey;
- } else {
- var2 = var1.charAt(this.keyPosition % var1.length());
- }
-
- if (this.isCaps) {
- var2 = Character.toUpperCase((char)var2);
- }
-
- try {
- this.rfb.writeKeyEvent(var2, true);
- } catch (IOException var4) {
- ((Throwable)var4).printStackTrace();
- }
-
- this.theCanvas.currentLetter = '\uffff';
- this.theCanvas.repaint();
- this.theCanvas.serviceRepaints();
- }
-
- public void pushKey(int var1) {
- if (var1 != this.lastKey) {
- if (this.lastKey != -1) {
- this.doSend();
- }
-
- this.lastKey = var1;
- this.keyPosition = 0;
- this.timer = new Thread(this);
- this.timer.start();
- } else {
- ++this.keyPosition;
- this.timer = new Thread(this);
- this.timer.start();
- }
-
- String var2 = (String)this.keys.get(new Integer(this.lastKey));
- char var3 = var2.charAt(this.keyPosition % var2.length());
- if (this.isCaps) {
- var3 = Character.toUpperCase(var3);
- }
-
- this.theCanvas.currentLetter = var3;
- this.theCanvas.repaint();
- this.theCanvas.serviceRepaints();
- }
-
- public void pushNumericKey(int var1) {
- char var2 = (Character)this.numKeys.get(new Integer(var1));
-
- try {
- this.rfb.writeKeyEvent(var2, true);
- } catch (IOException var4) {
- ((Throwable)var4).printStackTrace();
- }
-
- }
- }
-